﻿@{
    ViewBag.Title = "引入现有用户";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

<script type="text/javascript">
    $(function () {
        //当页面首次刷新的时候执行的事件
        initOrgTable();
        initUserTable();
    });

    function initOrgTable(queryData) {
        $('#orgTreeGrid').treegrid({
            url: '/OrgInfo/GetDataList',
            nowrap: true,
            autoRowHeight: false,
            striped: true,
            collapsible: true,
            rownumbers: true,
            remoteSort: false,
            idField: 'ID',
            treeField: 'OrgName',
            parentField: 'PID',
            checkOnSelect: true,
            selectOnCheck: true,
            singleSelect: true,
            queryParams: queryData,  //异步查询的参数
            columns: [[
                { title: '机构名称', field: 'OrgName', width: 200, sortable: true },
            ]],
            onClickRow: function (index, row) {
                //以下方法可行
                var selectedRow = $("#orgTreeGrid").treegrid("getSelected");
                if (selectedRow) {
                    $('#userDataGrid').datagrid('load', { orgID: selectedRow.ID });
                }
            }
        });
    }

    //初始化用户表
    function initUserTable(queryData) {
        $('#userDataGrid').datagrid({
            url: '/Account/GetDataListNoPage',
            nowrap: true,
            autoRowHeight: false,
            striped: true,
            collapsible: true,
            rownumbers: true,
            remoteSort: false,
            idField: 'ID',
            checkOnSelect: false,
            selectOnCheck: false,
            singleSelect: true,
            queryParams: queryData,  //异步查询的参数
            columns: [[
                { title: '用户名', field: 'UserName', width: 120, sortable: true },
                { title: '姓名', field: 'RealName', width: 80, sortable: true }
            ]],
            onClickRow: function (index, row) {
                //以下方法可行
                var selectedRow = $("#userDataGrid").datagrid("getSelected");
                if (selectedRow) {
                    //$("#hSelectedUserID") = selectedRow.ID;  //此方法不可行
                    document.getElementById("hSelectedUserID").value = selectedRow.ID;
                    document.getElementById("hSelectedUserName").value = selectedRow.UserName;
                }
            },
            //合并单元格
            //onLoadSuccess: function (data) {
            //    if (data.rows.length > 1) {
            //        var tTable = $("#userDataGrid");
            //        mergeCellsGroupByField(tTable, "UserName,RealName", 0, data.rows.length);
            //    }
            //}
        });
    }
    //var ImportUser = {
    //    //刷新机构
    //    ReloadOrg: function () {
    //        $("#orgTreeGrid").treegrid("reload");
    //    },

    //    //刷新用户
    //    ReloadUser: function () {
    //        $("#userDataGrid").datagrid("reload");
    //    }
    //}
</script>

<form id="form-importUser" method="post">
    <table>
        <tr>
            <td>
                <div region="west" data-options="border:false" style="width: 250px; height: 400px;">
                    <div class="easyui-panel" title="机构列表">
                        <table id="orgTreeGrid" style="height: 358px;"></table>
                    </div>
                </div>
            </td>
            <td>
                <div region="center" style="border-left: 0px; width: 255px; height: 400px;">
                    <div class="easyui-panel" title="用户列表">
                        <form id="form-purview" method="post">
                            <table id="userDataGrid" style="height: 358px;"></table>
                        </form>
                    </div>
                </div>
            </td>
        </tr>
    </table>
</form>
<input type="hidden" id="hSelectedUserID" />
<input type="hidden" id="hSelectedUserName" />